package view;

import model.Topic;
import geo2d.color;
import geo2d.pt;
import processing.core.PApplet;

public class DynamicView extends PApplet{
	int width = 600;
	int height = 600; 
	boolean update = true; 
	boolean grow = false; 
	Topic group ; 
	public void setup(){	
		initTopics(); 
		Topic.setFontandColor(this); 
		size(width, height, P2D);  
		smooth(); 
	}
	public void initTopics(){
		group = Topic.Root("", width, height); 
		group.addMember(color.ruby(), 100, 20);
		group.addMember(color.green(), 100, 20);
		group.addMember(color.cyan(), 100, 30);
		group.addMember(color.yellow(), 100, 40);
		group.addMember(color.magenta(), 100, 10); 
	}
	public void draw(){
		background(255); 
		noStroke(); 
		if (grow) group.grow(); 
		group.showColor(this);
		if (update) group.update(); 
	}
	public void mousePressed(){
		if (key=='s'){
			println("select disk"); 
			group.select(pt.mouse(this));
		}
	}
	public void mouseReleased(){
		//group.deselect(); 
	}
	public void keyPressed(){
		if (key=='a'){
			update=!update; 
			print("turn "); 
			if (update) print("on "); 
			else print("off "); 
			println("update"); 
		}
		if (key=='b'){
			grow=!grow; 
			print("turn "); 
			if (grow) print("on "); 
			else print("off "); 
			println("grow"); 
		}
		if (key=='c'){
			println("save a picture"); 
			saveFrame("pic/pic-####.png"); 
		}
		if (key=='d'){
			
			
		}	
	}
}
